﻿using System;
using System.Collections.Generic;
using UniRx;
using UniRx.Triggers;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x020005BE RID: 1470
	public class ENVControl : MonoBehaviour
	{
		// Token: 0x06002570 RID: 9584 RVA: 0x000DDC68 File Offset: 0x000DBE68
		private void OnClickRepeat()
		{
			Singleton<Studio>.Instance.envCtrl.repeat = ((Singleton<Studio>.Instance.envCtrl.repeat != BGMCtrl.Repeat.None) ? BGMCtrl.Repeat.None : BGMCtrl.Repeat.All);
			this.buttonRepeat.image.sprite = this.spriteRepeat[(Singleton<Studio>.Instance.envCtrl.repeat != BGMCtrl.Repeat.None) ? 1 : 0];
		}

		// Token: 0x06002571 RID: 9585 RVA: 0x000DDCD4 File Offset: 0x000DBED4
		private void OnClickStop()
		{
			Singleton<Studio>.Instance.envCtrl.Stop();
		}

		// Token: 0x06002572 RID: 9586 RVA: 0x000DDCE8 File Offset: 0x000DBEE8
		private void OnClickPlay()
		{
			Singleton<Studio>.Instance.envCtrl.Play();
		}

		// Token: 0x06002573 RID: 9587 RVA: 0x000DDCFC File Offset: 0x000DBEFC
		private void OnClickPause()
		{
		}

		// Token: 0x06002574 RID: 9588 RVA: 0x000DDD00 File Offset: 0x000DBF00
		private void OnClickExpansion()
		{
			this.objBottom.SetActive(!this.objBottom.activeSelf);
			this.buttonExpansion.image.sprite = this.spriteExpansion[(!this.objBottom.activeSelf) ? 0 : 1];
		}

		// Token: 0x06002575 RID: 9589 RVA: 0x000DDD54 File Offset: 0x000DBF54
		private void OnClickSelect(int _idx)
		{
			StudioNode studioNode = null;
			if (this.dicNode.TryGetValue(Singleton<Studio>.Instance.envCtrl.no, out studioNode))
			{
				studioNode.select = false;
			}
			Singleton<Studio>.Instance.envCtrl.no = _idx;
			if (this.dicNode.TryGetValue(Singleton<Studio>.Instance.envCtrl.no, out studioNode))
			{
				studioNode.select = true;
			}
		}

		// Token: 0x06002576 RID: 9590 RVA: 0x000DDDC4 File Offset: 0x000DBFC4
		private void InitList()
		{
			for (int i = 0; i < this.transformRoot.childCount; i++)
			{
				UnityEngine.Object.Destroy(this.transformRoot.GetChild(i).gameObject);
			}
			this.transformRoot.DetachChildren();
			foreach (KeyValuePair<int, Info.LoadCommonInfo> keyValuePair in Singleton<Info>.Instance.dicENVLoadInfo)
			{
				GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.objectNode);
				gameObject.transform.SetParent(this.transformRoot, false);
				StudioNode component = gameObject.GetComponent<StudioNode>();
				component.active = true;
				int idx = keyValuePair.Key;
				component.addOnClick = delegate()
				{
					this.OnClickSelect(idx);
				};
				component.text = keyValuePair.Value.name;
				this.dicNode.Add(idx, component);
			}
			StudioNode studioNode = null;
			if (this.dicNode.TryGetValue(Singleton<Studio>.Instance.envCtrl.no, out studioNode))
			{
				studioNode.select = true;
			}
		}

		// Token: 0x06002577 RID: 9591 RVA: 0x000DDF0C File Offset: 0x000DC10C
		private void Awake()
		{
			this.buttonRepeat.onClick.AddListener(new UnityAction(this.OnClickRepeat));
			this.buttonStop.onClick.AddListener(new UnityAction(this.OnClickStop));
			this.buttonPlay.onClick.AddListener(new UnityAction(this.OnClickPlay));
			this.buttonPause.onClick.AddListener(new UnityAction(this.OnClickPause));
			this.buttonExpansion.onClick.AddListener(new UnityAction(this.OnClickExpansion));
			this.InitList();
			this.UpdateAsObservable().Subscribe(delegate(Unit _)
			{
				this.imagePlayNow.enabled = Singleton<Studio>.Instance.envCtrl.play;
			});
		}

		// Token: 0x06002578 RID: 9592 RVA: 0x000DDFC4 File Offset: 0x000DC1C4
		private void OnEnable()
		{
			this.buttonRepeat.image.sprite = this.spriteRepeat[(Singleton<Studio>.Instance.envCtrl.repeat != BGMCtrl.Repeat.None) ? 1 : 0];
			foreach (KeyValuePair<int, StudioNode> keyValuePair in this.dicNode)
			{
				keyValuePair.Value.select = false;
			}
			StudioNode studioNode = null;
			if (this.dicNode.TryGetValue(Singleton<Studio>.Instance.envCtrl.no, out studioNode))
			{
				studioNode.select = true;
			}
		}

		// Token: 0x040025E0 RID: 9696
		[SerializeField]
		private GameObject objectNode;

		// Token: 0x040025E1 RID: 9697
		[SerializeField]
		private Transform transformRoot;

		// Token: 0x040025E2 RID: 9698
		[SerializeField]
		private Button buttonRepeat;

		// Token: 0x040025E3 RID: 9699
		[SerializeField]
		private Sprite[] spriteRepeat;

		// Token: 0x040025E4 RID: 9700
		[SerializeField]
		private Button buttonStop;

		// Token: 0x040025E5 RID: 9701
		[SerializeField]
		private Button buttonPlay;

		// Token: 0x040025E6 RID: 9702
		[SerializeField]
		private Image imagePlayNow;

		// Token: 0x040025E7 RID: 9703
		[SerializeField]
		private Button buttonPause;

		// Token: 0x040025E8 RID: 9704
		[SerializeField]
		private Button buttonExpansion;

		// Token: 0x040025E9 RID: 9705
		[SerializeField]
		private Sprite[] spriteExpansion;

		// Token: 0x040025EA RID: 9706
		[SerializeField]
		private GameObject objBottom;

		// Token: 0x040025EB RID: 9707
		private Dictionary<int, StudioNode> dicNode = new Dictionary<int, StudioNode>();
	}
}
